import { createRouter, createWebHistory } from 'vue-router';
import PurchaseOrderList from '@/views/purchase/PurchaseOrderList.vue'
import PurchaseOrderCreate from '@/views/purchase/PurchaseOrderCreate.vue'
import PurchaseOrderDetail from '@/views/purchase/PurchaseOrderDetail.vue'
import BookManagementView from '@/views/book/BookManagementView.vue';

const routes = [
  {
    path: '/dashboard',
    name: 'dashboard',
    component: function () {
      return import('../views/dashboard/DashboardView.vue');
    },
  },
  {
    path: '/book-retail',
    name: 'bookRetail',
    component: function () {
      return import('../views/book/BookRetailView.vue');
    },
  },
  {
    path: '/inventory-management',
    name: 'inventoryManagement',
    component: function () {
      return import('../views/inventory/InventoryManagementContainer.vue');
    },
    redirect: '/inventory-management/book-inventory',
    children: [
      {
        path: 'book-inventory',
        name: 'bookInventory',
        component: function () {
          return import('../views/book/BookInventoryView.vue');
        },
      },
      {
        path: 'goods-inventory',
        name: 'goodsInventory',
        component: function () {
          return import('../views/goods/GoodsInventoryView.vue');
        },
      },
    ],
  },
  {
    path: '/dealer-management',
    name: 'dealerManagement',
    component: function () {
      return import('../views/dealer/DealerManagementView.vue');
    },
  },
  {
    path: '/goods-management',
    name: 'goodsManagement',
    component: function () {
      return import('../views/goods/GoodsManagementContainer.vue');
    },
    redirect: '/goods-management/books',
    children: [
      {
        path: 'books',
        name: 'books',
        component: BookManagementView
      },
      {
        path: 'goods',
        name: 'goods',
        component: function () {
          return import('../views/goods/GoodsManagementView.vue');
        },
      },
    ],
  },
  {
    path: '/purchase-orders',
    name: 'PurchaseOrders',
    component: PurchaseOrderList
  },
  {
    path: '/purchase-orders/new',
    name: 'PurchaseOrderCreate',
    component: PurchaseOrderCreate
  },
  {
    path: '/purchase-orders/:id',
    name: 'PurchaseOrderDetail',
    component: PurchaseOrderDetail,
    props: true
  },
  {
    path: '/shipping-orders',
    name: 'shippingOrders',
    component: function () {
      return import('../views/shipping/ShippingOrdersView.vue');
    },
  },
  {
    path: '/',
    redirect: '/dashboard',
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;
